from instance import instance

true = 1
false = -1

def read_plain(file):
    
    '''
    @return: a list of instances 
    '''
    
    f = open(file)
    line = f.readline()
    
    instances = []
    
    while (line):
        line = line.split(',')
        inst = []
        for i in line[1:]:
        
            #print i
            inst.append(float(i))
            
        inst.append(1)
        
        np_inst = instance(list = inst, label = sign(float(line[0])))
        instances.append(np_inst)
        line = f.readline()
        
    return instances        

def sign(i):
    if i > 0: return true
    else: return false
    
def dot(x1, x2):
    return sum(x1*x2)

def kernel(d):
    return lambda x1, x2: -1+(dot(x1,x2))**d